<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>linux常用操作 | To Share</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/share/favicon.ico">
    <meta name="description" content="分享风雨，享受阳光">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/share/assets/css/0.styles.d7affcea.css" as="style"><link rel="preload" href="/share/assets/js/app.706684de.js" as="script"><link rel="preload" href="/share/assets/js/3.4685d505.js" as="script"><link rel="preload" href="/share/assets/js/1.b12738fb.js" as="script"><link rel="preload" href="/share/assets/js/50.3918e713.js" as="script"><link rel="preload" href="/share/assets/js/9.4e81f08e.js" as="script"><link rel="prefetch" href="/share/assets/js/10.9e95ce7b.js"><link rel="prefetch" href="/share/assets/js/11.e99410dc.js"><link rel="prefetch" href="/share/assets/js/12.e9afe07c.js"><link rel="prefetch" href="/share/assets/js/13.078dd281.js"><link rel="prefetch" href="/share/assets/js/14.6575b8f0.js"><link rel="prefetch" href="/share/assets/js/15.d942bb10.js"><link rel="prefetch" href="/share/assets/js/16.fd8cc40c.js"><link rel="prefetch" href="/share/assets/js/17.f1b1f2c6.js"><link rel="prefetch" href="/share/assets/js/18.b312ce79.js"><link rel="prefetch" href="/share/assets/js/19.a99d170f.js"><link rel="prefetch" href="/share/assets/js/20.cda2b911.js"><link rel="prefetch" href="/share/assets/js/21.d6062607.js"><link rel="prefetch" href="/share/assets/js/22.5a50eee4.js"><link rel="prefetch" href="/share/assets/js/23.be601eed.js"><link rel="prefetch" href="/share/assets/js/24.3d0b9811.js"><link rel="prefetch" href="/share/assets/js/25.c1c35d96.js"><link rel="prefetch" href="/share/assets/js/26.9a8b03ff.js"><link rel="prefetch" href="/share/assets/js/27.6c302f3e.js"><link rel="prefetch" href="/share/assets/js/28.5eb55960.js"><link rel="prefetch" href="/share/assets/js/29.8297842b.js"><link rel="prefetch" href="/share/assets/js/30.b453256b.js"><link rel="prefetch" href="/share/assets/js/31.6ce2e46f.js"><link rel="prefetch" href="/share/assets/js/32.cf3906ab.js"><link rel="prefetch" href="/share/assets/js/33.83680f76.js"><link rel="prefetch" href="/share/assets/js/34.dada508c.js"><link rel="prefetch" href="/share/assets/js/35.11a36f17.js"><link rel="prefetch" href="/share/assets/js/36.fc43ef74.js"><link rel="prefetch" href="/share/assets/js/37.af715eba.js"><link rel="prefetch" href="/share/assets/js/38.7ba3e6e1.js"><link rel="prefetch" href="/share/assets/js/39.cd1c9d09.js"><link rel="prefetch" href="/share/assets/js/4.c1f99423.js"><link rel="prefetch" href="/share/assets/js/40.8df0c044.js"><link rel="prefetch" href="/share/assets/js/41.e643a418.js"><link rel="prefetch" href="/share/assets/js/42.d809cd4f.js"><link rel="prefetch" href="/share/assets/js/43.5136999f.js"><link rel="prefetch" href="/share/assets/js/44.315a82bf.js"><link rel="prefetch" href="/share/assets/js/45.a4b04306.js"><link rel="prefetch" href="/share/assets/js/46.2e8ec77e.js"><link rel="prefetch" href="/share/assets/js/47.d6bde2ca.js"><link rel="prefetch" href="/share/assets/js/48.e8e85c15.js"><link rel="prefetch" href="/share/assets/js/49.fce2ff19.js"><link rel="prefetch" href="/share/assets/js/5.599dfd12.js"><link rel="prefetch" href="/share/assets/js/51.c5ddf50e.js"><link rel="prefetch" href="/share/assets/js/52.b6653f73.js"><link rel="prefetch" href="/share/assets/js/53.c0420367.js"><link rel="prefetch" href="/share/assets/js/54.0f64522f.js"><link rel="prefetch" href="/share/assets/js/55.1f9ce6fb.js"><link rel="prefetch" href="/share/assets/js/56.0a2fc30f.js"><link rel="prefetch" href="/share/assets/js/57.3b81efcb.js"><link rel="prefetch" href="/share/assets/js/58.c617dcad.js"><link rel="prefetch" href="/share/assets/js/59.5239e9d4.js"><link rel="prefetch" href="/share/assets/js/6.4e5676a9.js"><link rel="prefetch" href="/share/assets/js/60.b614d70b.js"><link rel="prefetch" href="/share/assets/js/61.f45be005.js"><link rel="prefetch" href="/share/assets/js/62.52121455.js"><link rel="prefetch" href="/share/assets/js/63.9f699597.js"><link rel="prefetch" href="/share/assets/js/64.01c4bf37.js"><link rel="prefetch" href="/share/assets/js/65.0f31fd4b.js"><link rel="prefetch" href="/share/assets/js/66.55dbbe80.js"><link rel="prefetch" href="/share/assets/js/67.fd9ba6df.js"><link rel="prefetch" href="/share/assets/js/68.c6c9e158.js"><link rel="prefetch" href="/share/assets/js/69.91757641.js"><link rel="prefetch" href="/share/assets/js/7.b8928c33.js"><link rel="prefetch" href="/share/assets/js/70.12f0a894.js"><link rel="prefetch" href="/share/assets/js/71.88c99794.js"><link rel="prefetch" href="/share/assets/js/72.e1d99c59.js"><link rel="prefetch" href="/share/assets/js/73.aee6f06a.js"><link rel="prefetch" href="/share/assets/js/74.b47532b0.js"><link rel="prefetch" href="/share/assets/js/75.1f1ab66e.js"><link rel="prefetch" href="/share/assets/js/8.56deb6eb.js">
    <link rel="stylesheet" href="/share/assets/css/0.styles.d7affcea.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container" data-v-130b300a><div data-v-130b300a><div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-130b300a data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>To Share</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>分享风雨，享受阳光</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <span data-v-25ba6db2>2018 - </span>
          2022
        </a></span></div></div> <div class="hide" data-v-130b300a><header class="navbar" data-v-130b300a><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/share/" class="home-link router-link-active"><!----> <span class="site-name">To Share</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/share/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/categories/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/flex/" class="nav-link"><i class="undefined"></i>
  flex
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/gui/" class="nav-link"><i class="undefined"></i>
  gui
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/nodeJs/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/share/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/share/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Docs
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/docs/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/flex/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/node/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/linux/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/gui/" class="nav-link"><i class="undefined"></i>
  GUI
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/zenglingchuan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-130b300a></div> <aside class="sidebar" data-v-130b300a><div class="personal-info-wrapper" data-v-39576ba9 data-v-130b300a><img src="/share/avatar.png" alt="author-avatar" class="personal-img" data-v-39576ba9> <!----> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>63</h3> <h6 data-v-39576ba9>文章</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>51</h3> <h6 data-v-39576ba9>标签</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/share/" class="nav-link"><i class="iconfont reco-home"></i>
  Home
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      Category
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/categories/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/flex/" class="nav-link"><i class="undefined"></i>
  flex
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/css/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/gui/" class="nav-link"><i class="undefined"></i>
  gui
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/linux/" class="nav-link"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/nodeJs/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/categories/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li></ul></div></div><div class="nav-item"><a href="/share/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  Tag
</a></div><div class="nav-item"><a href="/share/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  TimeLine
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      Docs
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/share/docs/git/" class="nav-link"><i class="undefined"></i>
  git
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/vue/" class="nav-link"><i class="undefined"></i>
  vue
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/flex/" class="nav-link"><i class="undefined"></i>
  css
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/js/" class="nav-link"><i class="undefined"></i>
  js
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/node/" class="nav-link"><i class="undefined"></i>
  nodeJs
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/docker/" class="nav-link"><i class="undefined"></i>
  docker
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/php/" class="nav-link"><i class="undefined"></i>
  php
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/linux/" aria-current="page" class="nav-link router-link-exact-active router-link-active"><i class="undefined"></i>
  linux
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/python/" class="nav-link"><i class="undefined"></i>
  python
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/gui/" class="nav-link"><i class="undefined"></i>
  GUI
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/golang/" class="nav-link"><i class="undefined"></i>
  golang
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/idea/" class="nav-link"><i class="undefined"></i>
  idea
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/site/" class="nav-link"><i class="undefined"></i>
  site
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/book/" class="nav-link"><i class="undefined"></i>
  book
</a></li><li class="dropdown-item"><!----> <a href="/share/docs/mysql/" class="nav-link"><i class="undefined"></i>
  mysql
</a></li></ul></div></div><div class="nav-item"><a href="https://gitee.com/zenglingchuan" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav> <ul class="sidebar-links"><li><a href="/share/docs/linux/" aria-current="page" class="active sidebar-link">linux常用操作</a></li><li><a href="/share/docs/linux/lnmp.html" class="sidebar-link">LNMP环境</a></li><li><a href="/share/docs/linux/lua.html" class="sidebar-link">Lua环境</a></li><li><a href="/share/docs/linux/work.html" class="sidebar-link">DevOps</a></li></ul> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-130b300a><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>linux常用操作</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><!---->
            
          <span data-v-25ba6db2>2018 - </span>
          2022
        </a></span></div></div> <div data-v-130b300a><main class="page"><section><div class="page-title"><h1 class="title">linux常用操作</h1> <div data-v-f875f3fc><!----> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>2022/5/14</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>linux</span><span class="tag-item" data-v-f875f3fc>nginx</span></i></div></div> <div class="theme-reco-content content__default"><div id="boxx" data-v-f4ca0dac><div data-v-f4ca0dac><p v-if="true" class="custom-block-title" data-v-f4ca0dac></p> <p v-if="true" data-v-f4ca0dac></p></div></div> <h2 id="设置服务器工作目录"><a href="#设置服务器工作目录" class="header-anchor">#</a> 设置服务器工作目录</h2> <p>登录服务器默认的入口目录</p> <ol><li><p>切换目录<code>cd ~</code> 或者 <code>cd /root</code>, 执行<code>ls -al</code>找到<code>.bashrc</code>文件</p></li> <li><p><code>.bashrc</code>文件结尾处加上 <code>cd 想要设置的默认路径</code></p></li> <li><p>加上后使文件生效，生效命令</p></li></ol> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token builtin class-name">source</span> .bashrc
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="强制跳转https"><a href="#强制跳转https" class="header-anchor">#</a> 强制跳转https</h2> <p>http强制跳转https, 比如,访问<code>http://www.baidu.com/</code>,默认直接跳转<code>https://www.baidu.com/</code></p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>server
<span class="token punctuation">{</span>
    listen <span class="token number">80</span><span class="token punctuation">;</span>
    server_name www.baidu.com<span class="token punctuation">;</span>
    rewrite ^<span class="token punctuation">(</span>.*<span class="token punctuation">)</span>$ https://<span class="token variable">$host</span><span class="token variable">$1</span> permanent<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">#  nginx禁止恶意解析域名</span>
server <span class="token punctuation">{</span>
    listen <span class="token number">80</span> default<span class="token punctuation">;</span>
    server_name  <span class="token string">&quot;&quot;</span><span class="token punctuation">;</span>
    <span class="token builtin class-name">return</span>  <span class="token number">444</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="文件上传500问题"><a href="#文件上传500问题" class="header-anchor">#</a> 文件上传500问题</h2> <div class="custom-block tip"><p class="title">描述</p><p>nginx配置文件<code>client_body_buffer_size</code>请求大小, 加入是<code>2M</code>, 当上传文件超过了<code>2M</code>; 换句话说,只有当上传的请求体超出缓存区大小时，上传的文件会写到临时文件中, nginx中临时文件配置为: <code>client_body_temp_path</code>;</p></div><h3 id="问题原因"><a href="#问题原因" class="header-anchor">#</a> 问题原因</h3> <ol><li><p>文件大小超过了<code>client_body_buffer_size</code></p></li> <li><p><code>client_body_temp_path</code>的临时文件路径居然没有写权限, 我linux路径为<code>/www/server/nginx/client_body_temp_path</code>, 我php是<code>www</code>用户执行, 没有权限;</p></li></ol> <p>以上两个原因导致了返回<code>500</code>错误。</p> <h3 id="解决"><a href="#解决" class="header-anchor">#</a> 解决</h3> <ol><li><p><code>client_body_buffer_size</code> 尽量设置的大点，这是基于速度的考虑，如果因为设置的过小，导致上传的文件老要写磁盘，那速度就太慢了。</p></li> <li><p><code>client_body_temp_path</code> 路径要有可写权限;</p></li> <li><p><code>client_max_body_size</code> 设置上传文件的最大值，这个是基于安全的考虑，我们认为正常用户不会或者基本不会上传太大的文件。可以设置为<code>client_max_body_size 100m;</code>  或者按照自己的业务来设置这个值。</p></li></ol> <h2 id="命令连接符"><a href="#命令连接符" class="header-anchor">#</a> 命令连接符</h2> <div class="custom-block tip"><p class="title">提示</p><p>一般情况下, 我们常用<code>&amp;&amp;</code>, 用来保证每条命令都顺利执行</p></div><h3 id=""><a href="#" class="header-anchor">#</a> <code>&amp;&amp;</code></h3> <p>语法格式:</p> <div class="language-shell line-numbers-mode"><pre class="language-shell"><code>command1 <span class="token operator">&amp;&amp;</span> command2
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="custom-block warning"><p class="title">注意</p><p><code>&amp;&amp;</code>左边的command1执行成功(返回0表示成功)后，<code>&amp;&amp;</code>右边的command2才能被执行</p></div><h3 id="-2"><a href="#-2" class="header-anchor">#</a> <code>;</code></h3> <p>每个命令之间用<code>;</code>隔开, 不会影响其它命令的执行, 换句话说, 各个命令都会执行, 但不保证每个命令都执行</p> <h3 id="-3"><a href="#-3" class="header-anchor">#</a> <code>||</code></h3> <p>每个命令之间用<code>||</code>隔开, <code>||</code>是或的意思, 只有前面的命名执行失败后才去执行下一条命名, 指到执行成功一条命令为止</p> <h2 id="shell脚本"><a href="#shell脚本" class="header-anchor">#</a> shell脚本</h2> <div class="custom-block tip"><p class="title">注意</p><ol><li>date和后面的<code>+</code>之间有空格</li> <li>示例是 Shell 脚本一次性执行多条语句，并可以统计时间</li></ol></div><div class="language-shell line-numbers-mode"><pre class="language-shell"><code><span class="token shebang important">#! /bin/bash</span>
<span class="token assign-left variable">startTime</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">date</span> +%Y%m%d-%H:%M<span class="token variable">`</span></span> <span class="token comment"># 脚本执行的开始时间</span>
<span class="token assign-left variable">startTime_s</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">date</span> +%s<span class="token variable">`</span></span> <span class="token comment"># 秒</span>
<span class="token builtin class-name">cd</span> /wwwroot <span class="token operator">&amp;&amp;</span>  <span class="token comment"># 切换到/wwwroot目录</span>
<span class="token function">mkdir</span> <span class="token builtin class-name">test</span> <span class="token operator">&amp;&amp;</span> <span class="token comment"># 创建test目录</span>
<span class="token builtin class-name">cd</span> <span class="token builtin class-name">test</span> <span class="token operator">&amp;&amp;</span> <span class="token comment"># 切换到test目录</span>
<span class="token builtin class-name">pwd</span>  <span class="token comment"># 显示当前工作目录</span>
<span class="token assign-left variable">endTime</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">date</span> +%Y%m%d-%H:%M<span class="token variable">`</span></span>
<span class="token assign-left variable">endTime_s</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">date</span> +%s<span class="token variable">`</span></span>
<span class="token assign-left variable">sumTime</span><span class="token operator">=</span>$<span class="token punctuation">[</span> <span class="token variable">$endTime_s</span> - <span class="token variable">$startTime_s</span> <span class="token punctuation">]</span> <span class="token comment"># $[] ：用于整数运算</span>
<span class="token comment"># echo shell中输出变量</span>
<span class="token builtin class-name">echo</span> <span class="token string">&quot;<span class="token variable">$startTime</span> ----&gt;  <span class="token variable">$endTime</span>&quot;</span>  <span class="token string">&quot;Totl: <span class="token variable">$sumTime</span> seconds&quot;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="test-sh和source-test-sh区别"><a href="#test-sh和source-test-sh区别" class="header-anchor">#</a> ./test.sh和source test.sh区别</h2> <div class="custom-block tip"><p class="title">区别</p><ol><li><p><code>./test.sh</code> 重新建立一个子shell，在子shell中执行脚本里面的语句，该子shell继承父shell的环境变量，但子shell新建的、改变的变量不会被带回父shell，除非使用</p></li> <li><p>source test.sh 这个命令其实只是简单地读取脚本里面的语句依次在当前shell里面执行，没有建立新的子shell。那么脚本里面所有新建、改变变量的语句都会保存在当前shell里</p></li></ol></div><h2 id="文件权限问题"><a href="#文件权限问题" class="header-anchor">#</a> 文件权限问题</h2> <div class="language-text line-numbers-mode"><pre class="language-text"><code> ypy@ubuntu:~$ ls -l
754    drwxr-xr--  2 ypy  ypy     4096 Nov 30 18:33 Desktop/
754    drwxr-xr--  2 ypy  ypy     4096 Nov 30 18:33 Documents/
754    drwxr-xr--  2 ypy  ypy     4096 Dec  1 16:01 Downloads/
774    -rwxrwxr--  2 ypy  ypy     4096 Feb  8 19:59 exercise
664    -rw-rw-r--  2 ypy  ypy     4096 Dec  1 16:02 file.sh
       0123456789  ~~~ 左边的数字0到9是最`drwxr-xr--`的标号, 方便注释描述
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><ol><li>r=4, w=2, x=1, 这个数值是linux定义的; 7 = 4 + 2 + 1</li> <li>r=4表示读权限, w=2表示写权限, x=1表示可执行权限</li> <li>标号0的位置, d 代表的是目录文件, - 代表普通文件</li> <li>标号123的位置表示用户,用u表示; 标号456的位置表示用户组, 用g表示; 标号789的位置表示其他用户, 用o表示;</li> <li>修改文件访问权限的方法--mode法</li></ol> <div class="language-text line-numbers-mode"><pre class="language-text"><code>权限     	    数值
rwx rw- r–	    764
rw- r–  r–	    644
rw- rw- r–	    664

u 代表用户.
g 代表用户组.
o 代表其他.
a 代表所有

chmod u+x file 只授予这个文件的所属者执行的权限 
chmod ugo+r file 所有人皆可读取

修改文件访问权限的方法--数字法
chmod 600 file 只授予这个文件的所属者读写权限 
chmod -R 600 file 授予这个文件夹及其里面的所有文件的所属者读写权限
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br></div></div><h2 id="nginx配置反向代理"><a href="#nginx配置反向代理" class="header-anchor">#</a> nginx配置反向代理</h2> <div class="custom-block warning"><p class="title">提示</p><p>Nginx作为近年来较火的反向代理服务器，安装在目的主机端，主要用于转发客户机请求，后台有多个http服务器提供服务，nginx的功能就是把请求转发给后面的服务器，决定哪台目标主机来处理当前请求。</p></div><blockquote><p>需求:<br>
vue项目和后端项目之间跨域问题<br>
API请求地址为:  http://127.0.0.1:8000/upload/image<br>
前端访问地址为: http://127.0.0.1:8001/api/upload/image<br>
目前前端访问多了一个<code>api</code>, 且端口号不一样; 我们要利用<code>rewrite</code>指令对地址进行重写, 移除<code>api</code></p></blockquote> <ul><li>代理配置</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>location /api/upload <span class="token punctuation">{</span>
    proxy_pass http://127.0.0.1:8000<span class="token punctuation">;</span>
    proxy_connect_timeout <span class="token number">600</span><span class="token punctuation">;</span>
    proxy_read_timeout <span class="token number">600</span><span class="token punctuation">;</span>
    rewrite <span class="token string">&quot;^/api/(.*)$&quot;</span> /<span class="token variable">$1</span> <span class="token builtin class-name">break</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><ul><li>配置说明
<ul><li><code>proxy_pass</code> 反向代理, 这次我们代理到<code>http://127.0.0.1:8000</code>这个地址</li> <li><code>&lt;font color='red'&gt;</code>rewrite &quot;^/api/(.*)$ /$1 break;<code>&lt;/font&gt;</code> 路径重写</li> <li><code>rewrite</code>语法: <code>rewrite</code>(关键字) + <code>&lt;regex&gt;</code>(正则) + <code>&lt;replacement&gt;</code>(替代内容) + <code>[flag]</code>;(flag标记)</li> <li><code>proxy_connect_timeout</code>后端服务器连接的超时时间_发起握手等候响应超时时间</li> <li><code>proxy_read_timeout</code> 该指令设置与代理服务器的读超时时间</li> <li><code>rewrite &quot;^/api/(.*)$&quot; /$1 break;</code><br>配置说明:
<ul><li><code>rewrite</code>为固定关键字，表示开始进行rewrite匹配规则</li> <li><code>^/api/(.*)$</code> 这是一个正则表达式，匹配含有<code>/api/</code>的域名和后面的路径地址</li> <li><code>/$1</code> 是取自 <code>^/api/(.*)$</code>部分()里的内容, 匹配成功后跳转到的URL</li> <li><code>break</code> 本条规则匹配完成即终止，不再匹配后面的任何规则</li></ul></li></ul></li></ul> <h2 id="vue打包部署后刷新404问题"><a href="#vue打包部署后刷新404问题" class="header-anchor">#</a> Vue打包部署后刷新404问题</h2> <div class="custom-block tip"><p class="title"></p><p>处理Vue部署history模式刷新404问题</p></div><ul><li><p>原因分析<br>
浏览器地址栏  <code>http://localhost:8080/#/home/news</code>  带#号路径为hash模式, 不带#号的为history模式</p> <div class="custom-block warning"><p class="title"></p><p>hash工作模式中,  url路径<code>#</code>及其之后的路径字符串,这里就是<code>#/home/news</code>是hash值,  <font style="color:red;"><strong>hash值</strong></font>在http请求中, 不会带给服务器,  所以部署上线不会出现404问题; 然后history工作模式中, 所有路径在http中都会带给服务器, 服务器区分不开前端路由和后端路由, 服务器识别不了前端路由的时候, 刷新就会报404问题;</p></div></li> <li><p>解决思路</p></li></ul> <div class="custom-block warning"><p class="title"></p><p>解决问题的核心就是通过配置文件<font style="color:red;"><strong>区分开前端路由和后端路由</strong></font>; 找不到后端路由, 通过重定向, 访问<code>index.html</code></p></div><ul><li>nginx解决方案</li></ul> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>location / <span class="token punctuation">{</span>   
    try_files <span class="token variable">$uri</span> <span class="token variable">$uri</span>/ @router<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

location @router <span class="token punctuation">{</span>
  rewrite ^.*$ /index.html last<span class="token punctuation">;</span>
  <span class="token comment"># 匹配所有  /index.html last;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><ul><li><p>配置分析</p> <ul><li>理解: <code>try_files $uri $uri/ @aab</code></li></ul> <blockquote><p>@ 表示配置文件中预定义标记点</p></blockquote> <ul><li><code>try_files</code> 尝试读取文件, 它尝试读取的事静态文件</li> <li>第一个参数<code>$url</code> , 它是nginx的一个变量, 存放着用户访问的地址<div class="language-sh line-numbers-mode"><pre class="language-sh"><code>比如: 
<span class="token number">1</span>. http://www.xxx.com/index.html,  那么<span class="token variable">$uri</span>就是 /index
<span class="token number">2</span>. http://localhost:8080/home/news, 那么<span class="token variable">$uri</span>就是 /home/news
<span class="token number">3</span>. http://localhost/example, 那么<span class="token variable">$uri</span>就是 /example
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div></li> <li>第二个参数<code>$uri/</code> 代表访问的是一个目录<div class="language-sh line-numbers-mode"><pre class="language-sh"><code>比如：
<span class="token number">1</span>. http://www.xxx.com/hello/test/ ，那么<span class="token variable">$uri</span>/就是 /hello/test/
<span class="token number">2</span>. http://localhost/example, 那么<span class="token variable">$url</span>就是 /example/
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div></li> <li>配置理解<div class="custom-block warning"><p class="title"></p></div></li></ul> <p>当用户尝试请求 <code>http://localhost/example</code>时<br><br> <code>try_files</code> 尝试去网站根目录 ( <code>/root</code> ) 读取用户这个文件,  如果存在名为 <code>/root/example</code> (这个就是$uri文件, 第一个变量) 的文件, 就直接把这个文件的内容返回给用户;   如果不存在, 继续读取第二个变量<code>$uri/</code>, 增加了一个<code>/</code>, 也就是看 <code>/root/example</code>/ 这个目录是否存在, 如果存在, 这个目录直接返回给用户, 如果不存在, 直接跳转到第三个参数<code>@aab</code>, 这里就是通提供给预定义标记点, 跳转到下面的<code>@router</code>, 标记点<code>@router</code>和下面的<code>@router</code>保持一致</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>  location @router <span class="token punctuation">{</span>
    rewrite ^.*$ /index.html last<span class="token punctuation">;</span>  
  <span class="token comment">#     匹配所有 /index.html last;</span>
  <span class="token punctuation">}</span>
  <span class="token comment"># last标记 重写 url 后，会再从 server 走一遍匹配流程</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>:::</p> <ul><li><code>rewrite ^.*$ /index.html last;</code>:   匹配所有  /index.html last;  所有的<code>$url</code>替换成真实的url(/index.html),后, (last)再从server走一遍匹配流程, 就走到了http://localhost/index.html; 访问到了文件</li> <li>扩展: laravel伪静态<br>
如果都找不到, 就会 fall back 到 try_files 的最后一个选项 /index.php，发起一个内部 “子请求”，也就是相当于 nginx 发起一个 HTTP 请求到 http://localhost/index.php<div class="language-sh line-numbers-mode"><pre class="language-sh"><code>  try_files <span class="token variable">$uri</span> <span class="token variable">$uri</span>/ /index.php?<span class="token variable">$query_string</span><span class="token punctuation">;</span>   
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li></ul></li></ul> <h2 id="后台启动任务"><a href="#后台启动任务" class="header-anchor">#</a> 后台启动任务</h2> <ul><li><p>背景<br>
当我们在终端启动服务或者训练模型时，启动命令往往会阻塞自己，即无法在终端继续输入，同时为了保证终端关闭不影响进程中断，需要在后台启动进程 ;</p></li> <li><p>命令</p> <ul><li>后台启动常用的命令:  <code>nohup command 2&gt;&amp;1 &amp; 或者 nohup command 2&gt;&gt;&amp;1 &amp;</code></li> <li>示例： <code>nohup python my.py &gt;&gt;/home/xxx/my.log 2&gt;&amp;1 &amp;</code></li> <li>在bash shell中：
<ul><li><code>0</code>：代表标准输入，即键盘输入的</li> <li><code>1</code>：代表标准输出，即输出到显示屏的内容</li> <li><code>2</code>：代表标准错误，即报错内容</li> <li><code>&gt;&gt;</code>: 代表追加, <code>&gt;</code>会让日志文件的内容清空</li> <li><code>nohup</code>: 表示不挂断地执行命令，即便退出当前终端。同时会将屏幕的标准输出追加到默认文件<code>nohup.out</code>文件</li> <li><code>&amp;</code>：表示在后台执行命令</li> <li><code>2&gt;&amp;1</code>: 不能用空格，代表将错误内容重定向到标准输出中。</li></ul></li></ul></li> <li><p>命令解析<br></p> <div class="custom-block warning"><p class="title"></p><p><font style="color:red;"><strong>假如有如下命令</strong></font>:<br> <code>nohup /usr/bin/php /www/wwwroot/school/artisan swoole &gt;&gt; /home/my.log 2&gt;&amp;1 &amp;</code></p></div></li> <li><p><code>nohup /usr/bin/php /www/wwwroot/school/artisan swoole</code> 表示php不间断低执行swoole脚本</p></li> <li><p><code>/www/wwwroot/school/artisan swoole &gt;&gt; /home/my.log</code>这部分等同于 <code>/www/wwwroot/school/artisan swoole 1&gt;&gt; /home/my.log</code>，即省略了标准输出1;</p></li> <li><p>上面命令可以拆解为:</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">nohup</span> /usr/bin/php /www/wwwroot/school/artisan swoole <span class="token operator"><span class="token file-descriptor important">1</span>&gt;&gt;</span> /home/my.log <span class="token operator">&amp;</span>
<span class="token function">nohup</span> /usr/bin/php /www/wwwroot/school/artisan swoole <span class="token operator"><span class="token file-descriptor important">2</span>&gt;&gt;</span> /home/my.log <span class="token operator">&amp;</span>

<span class="token operator"><span class="token file-descriptor important">2</span>&gt;</span><span class="token file-descriptor important">&amp;1</span>中的 <span class="token operator">&amp;</span> 是为了区分 <span class="token number">1</span> 是文件名 还是标准输出1 ，如果省略掉则变成了输出到文件1中
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>:::</p></li> <li><p>nohup不输出到文件</p> <ul><li>nohup启动服务时，会默认生成 nohup.out 文件，这样可能会占据相当一部分的磁盘空间，所以便会有一种需求 - 不让nohup 产生日志。</li> <li>其实是没办法不让 nohup 产生日志的，但是可以利用 linux 的 黑洞 /dev/null ，重定向到它的信息会消失，如果我们不需要保存程序运行时的所有信息时，就可以将信息重定向到 /dev/null 。</li> <li><font style="color:red;"><strong>示例如下</strong></font>:<div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">nohup</span> /usr/bin/php /www/wwwroot/school/artisan swoole <span class="token operator">&gt;</span> /dev/null <span class="token operator"><span class="token file-descriptor important">2</span>&gt;</span><span class="token file-descriptor important">&amp;1</span> <span class="token operator">&amp;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></li></ul></li></ul> <h2 id="反向代理之后获取真实ip-php版本"><a href="#反向代理之后获取真实ip-php版本" class="header-anchor">#</a> 反向代理之后获取真实ip(php版本)</h2> <div class="custom-block tip"><p class="title"></p><p>使用VUE前后端分离开发, 后端使用Laravel框架, 想要获取到用户的真实IP地址;</p> <p>因为分离开发不同源跨域问题 所以只能进行前端Nginx反向代理; 反向代理之后, 发现返回的只是代理服务器的IP地址。</p></div><p><font color="blue"><strong>在前端Nginx代理配置写入</strong></font></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 在前端Nginx代理配置写入</span>
location /web <span class="token punctuation">{</span>
    proxy_pass http://127.0.0.1:9099<span class="token punctuation">;</span>
    proxy_connect_timeout <span class="token number">600</span><span class="token punctuation">;</span>
    proxy_read_timeout <span class="token number">600</span><span class="token punctuation">;</span>
    rewrite <span class="token string">&quot;^/web/(.*)$&quot;</span> /<span class="token variable">$1</span> <span class="token builtin class-name">break</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
<span class="token comment"># 新增配置下面两行</span>
proxy_set_header X-Forwarded-For <span class="token variable">$remote_addr</span><span class="token punctuation">;</span>
proxy_set_header X-Forwarded-For <span class="token variable">$proxy_add_x_forwarded_for</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p><font color="blue"><strong>插入之后进行Nginx重启发现warning错误</strong></font></p> <div class="custom-block danger"><p class="title"></p><p>Starting nginx: nginx: [warn] could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64;</p> <p>ignoring proxy_headers_hash_bucket_size</p></div><p><font color="blue"><strong>在nginx.conf配置文件里面的http代码块里面加入下面配置代码解决</strong></font></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>http<span class="token punctuation">{</span>
<span class="token punctuation">..</span>.
<span class="token comment"># 新加入配置代码</span>
proxy_headers_hash_max_size <span class="token number">51200</span><span class="token punctuation">;</span>
proxy_headers_hash_bucket_size <span class="token number">6400</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p><font color="blue"><strong>真实的ip地址就是:  <code>$_SERVER['HTTP_X_FORWARDED_FOR']</code></strong></font> 。</p> <h2 id="常用linux命令"><a href="#常用linux命令" class="header-anchor">#</a> 常用linux命令</h2> <h3 id="ls命令"><a href="#ls命令" class="header-anchor">#</a> ls命令</h3> <div class="custom-block tip"><p class="title"></p><p>用于显示指定工作目录下之内容（列出目前工作目录所含之文件及子目录)。</p></div><p><font color="blue"><strong>语法: </strong></font></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ls</span> <span class="token punctuation">[</span>-alrtAFR<span class="token punctuation">]</span> <span class="token punctuation">[</span>name<span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>-a 显示所有文件及目录 (. 开头的隐藏文件也会列出)</li> <li>-l 除文件名称外，亦将文件型态、权限、拥有者、文件大小等资讯详细列出</li> <li>-r 将文件以相反次序显示(原定依英文字母次序)</li> <li>-t 将文件依建立时间之先后次序列出</li> <li>-A 同 -a ，但不列出 &quot;.&quot; (目前目录) 及 &quot;..&quot; (父目录)</li> <li>-F 在列出的文件名称后加一符号；例如可执行档则加 &quot;*&quot;, 目录则加 &quot;/&quot;</li> <li>-R 若目录下有文件，则以下之文件亦皆依序列出</li></ul> <p><font color="blue"><strong>按照时间升序显示文件信息:</strong></font></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ls</span> -lrt --full-time
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><font color="blue"><strong>按照时间降序显示文件信息(最新修改的排在前面):</strong></font></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">ls</span> -lt --full-time
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="top命令"><a href="#top命令" class="header-anchor">#</a> top命令</h3> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>root@iZjalzfbm2offnZ:/wwwroot<span class="token comment"># top</span>
<span class="token function">top</span> - <span class="token number">10</span>:33:18 up <span class="token number">184</span> days, <span class="token number">17</span>:19,  <span class="token number">1</span> user,  load average: <span class="token number">0.11</span>, <span class="token number">0.09</span>, <span class="token number">0.23</span>
Tasks: <span class="token number">506</span> total,   <span class="token number">1</span> running, <span class="token number">505</span> sleeping,   <span class="token number">0</span> stopped,   <span class="token number">0</span> zombie
%Cpu<span class="token punctuation">(</span>s<span class="token punctuation">)</span>:  <span class="token number">1.0</span> us,  <span class="token number">1.0</span> sy,  <span class="token number">0.0</span> ni, <span class="token number">98.0</span> id,  <span class="token number">0.0</span> wa,  <span class="token number">0.0</span> hi,  <span class="token number">0.0</span> si,  <span class="token number">0.0</span> st
MiB Mem <span class="token builtin class-name">:</span>   <span class="token number">3936.1</span> total,    <span class="token number">400.0</span> free,   <span class="token number">1066.8</span> used,   <span class="token number">2469.4</span> buff/cache
MiB Swap:   <span class="token number">4096.0</span> total,    <span class="token number">658.5</span> free,   <span class="token number">3437.5</span> used.   <span class="token number">2590.7</span> avail Mem 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><font color="red"><strong>第一行:</strong></font>
当前时间，系统运行时间，登录用户数量，平均负载（分别在5，10，15分钟内)</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token function">top</span> - <span class="token number">10</span>:33:18 up <span class="token number">184</span> days, <span class="token number">17</span>:19,  <span class="token number">1</span> user,  load average: <span class="token number">0.11</span>, <span class="token number">0.09</span>, <span class="token number">0.23</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>当前时间是10:33:18</li> <li>系统运行了184天,17小时19分</li> <li>当前登录用户的数量: 1个用户</li> <li>相应最近5、10和15分钟内的平均负载为 0.11, 0.09, 0.23</li></ul> <p><font color="red"><strong>第二行:</strong></font>
显示了系统的进程总数，后面是相应的状态下的进程</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>Tasks: <span class="token number">506</span> total,   <span class="token number">1</span> running, <span class="token number">505</span> sleeping,   <span class="token number">0</span> stopped,   <span class="token number">0</span> zombie
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>一共506个进程</li> <li>1个是running状态进程</li> <li>505个sleeping状态进程</li> <li>0个stopped状态进程</li> <li>0个zombie状态进程, 也叫僵尸进程, 就是，这个进程其实已经结束了，它仅仅在进程列表中保留一个位置，记载该进程的状态信息等，僵尸进程不再占有内存空间，没有可执行程序，也不能被调用。这个进程中存储着进程的各种信息，占用cpu啊，运行时间之类的。这个进程会被其父进程收集它的信息。</li></ul> <p><font color="red"><strong>第三行:</strong></font>
显示cpu的各种信息</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>%Cpu<span class="token punctuation">(</span>s<span class="token punctuation">)</span>:  <span class="token number">1.0</span> us,  <span class="token number">1.0</span> sy,  <span class="token number">0.0</span> ni, <span class="token number">98.0</span> id,  <span class="token number">0.0</span> wa,  <span class="token number">0.0</span> hi,  <span class="token number">0.0</span> si,  <span class="token number">0.0</span> st
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><ul><li>us：用户空间占cpu百分比</li> <li>sy：内核空间占cpu百分比</li> <li>ni：用户进程空间内改变过优先级的进程占用cpu百分比</li> <li>id：空闲cpu百分比</li> <li>wa：等待输入输出的cpu时间百分比</li> <li>hi：硬中断（处理硬件中断的cpu时间）</li> <li>si：软中断（处理软件中断的cpu时间）</li></ul> <p><font color="red"><strong>第四,五行:</strong></font>
内存使用, 第四行是物理内存使用, 第五行是虚拟内存使用(交换空间)。</p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code>MiB Mem <span class="token builtin class-name">:</span>   <span class="token number">3936.1</span> total,    <span class="token number">400.0</span> free,   <span class="token number">1066.8</span> used,   <span class="token number">2469.4</span> buff/cache
MiB Swap:   <span class="token number">4096.0</span> total,    <span class="token number">658.5</span> free,   <span class="token number">3437.5</span> used.   <span class="token number">2590.7</span> avail Mem 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>物理内存:  全部可用内存(total);   空闲内存(free);   已使用内存(used);   缓存内存(buff/cache)<br>
虚拟内存:  全部可用内存(total);   空闲内存(free);   已使用内存(used);   缓冲交换空间(avail Mem)</p> <p><font color="red"><strong>字段/列</strong></font></p> <div class="language-sh line-numbers-mode"><pre class="language-sh"><code> PID   <span class="token environment constant">USER</span>     PR    NI    VIRT    RES    SHR     S   %CPU   %MEM      TIME+           COMMAND                                                                                                                                                                 
<span class="token number">1131801</span> root    <span class="token number">10</span>   -10   <span class="token number">157164</span>   <span class="token number">59152</span>  <span class="token number">10332</span>   S   <span class="token number">2.3</span>    <span class="token number">1.5</span>     <span class="token number">908</span>:26.95          AliYunDun                                                                                                                                                               
 <span class="token number">743108</span> root    <span class="token number">20</span>   <span class="token number">0</span>     <span class="token number">1278484</span>  <span class="token number">46284</span>  <span class="token number">8984</span>    S   <span class="token number">0.7</span>    <span class="token number">1.1</span>     <span class="token number">991</span>:45.21          python3                                                                                                                                                                 
<span class="token number">2712198</span> root    <span class="token number">20</span>   <span class="token number">0</span>     <span class="token number">658016</span>   <span class="token number">58448</span>  <span class="token number">9996</span>    S   <span class="token number">0.7</span>    <span class="token number">1.5</span>     <span class="token number">554</span>:13.99          python3 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><ul><li>PID   进程ID，进程的唯一标识符</li> <li>USER  进程所有者的实际用户名</li> <li>PR    进程的调度优先级。这个字段的一些值是’rt’。这意味这这些进程运行在实时态。</li> <li>NI    进程的nice值（优先级）。越小的值意味着越高的优先级。</li> <li>VIRT  进程使用的虚拟内存。</li> <li>RES   驻留内存大小。驻留内存是任务使用的非交换物理内存大小。</li> <li>SHR   SHR是进程使用的共享内存。</li> <li>S     这个是进程的状态。它有以下不同的值:
<ul><li>D – 不可中断的睡眠态。</li> <li>R – 运行态</li> <li>S – 睡眠态</li> <li>T – 被跟踪或已停止</li> <li>Z – 僵尸态</li></ul></li> <li>%CPU 自从上一次更新时到现在任务所使用的CPU时间百分比。</li> <li>%MEM  进程使用的可用物理内存百分比。</li> <li>TIME+ 任务启动后到现在所使用的全部CPU时间，精确到百分之一秒。</li> <li>COMMAND 运行进程所使用的命令。</li></ul> <h2 id="nginx代理之后-访问不到静态资源"><a href="#nginx代理之后-访问不到静态资源" class="header-anchor">#</a> nginx代理之后, 访问不到静态资源</h2> <p>nginx配置修改：配置静态文件的映射</p> <div class="language-conf line-numbers-mode"><pre class="language-text"><code>location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
    # 图片代理地址
    proxy_pass http://localhost:1111;  
}
location ~ .*\.(js|css)?$
{
    # js/css
	proxy_pass http://www.xxx.com:8978;
}
	
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">2022/6/24 09:57:29</span></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/share/docs/linux/lnmp.html">
            LNMP环境
          </a></span></p></div> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#设置服务器工作目录" class="sidebar-link reco-side-设置服务器工作目录" data-v-cb1513f6>设置服务器工作目录</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#强制跳转https" class="sidebar-link reco-side-强制跳转https" data-v-cb1513f6>强制跳转https</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#文件上传500问题" class="sidebar-link reco-side-文件上传500问题" data-v-cb1513f6>文件上传500问题</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/linux/#问题原因" class="sidebar-link reco-side-问题原因" data-v-cb1513f6>问题原因</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/linux/#解决" class="sidebar-link reco-side-解决" data-v-cb1513f6>解决</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#命令连接符" class="sidebar-link reco-side-命令连接符" data-v-cb1513f6>命令连接符</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/linux/#" class="sidebar-link reco-side-" data-v-cb1513f6>&amp;&amp;</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/linux/#-2" class="sidebar-link reco-side--2" data-v-cb1513f6>;</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/linux/#-3" class="sidebar-link reco-side--3" data-v-cb1513f6>||</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#shell脚本" class="sidebar-link reco-side-shell脚本" data-v-cb1513f6>shell脚本</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#test-sh和source-test-sh区别" class="sidebar-link reco-side-test-sh和source-test-sh区别" data-v-cb1513f6>./test.sh和source test.sh区别</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#文件权限问题" class="sidebar-link reco-side-文件权限问题" data-v-cb1513f6>文件权限问题</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#nginx配置反向代理" class="sidebar-link reco-side-nginx配置反向代理" data-v-cb1513f6>nginx配置反向代理</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#vue打包部署后刷新404问题" class="sidebar-link reco-side-vue打包部署后刷新404问题" data-v-cb1513f6>Vue打包部署后刷新404问题</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#后台启动任务" class="sidebar-link reco-side-后台启动任务" data-v-cb1513f6>后台启动任务</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#反向代理之后获取真实ip-php版本" class="sidebar-link reco-side-反向代理之后获取真实ip-php版本" data-v-cb1513f6>反向代理之后获取真实ip(php版本)</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#常用linux命令" class="sidebar-link reco-side-常用linux命令" data-v-cb1513f6>常用linux命令</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/linux/#ls命令" class="sidebar-link reco-side-ls命令" data-v-cb1513f6>ls命令</a></li><li class="level-3" data-v-cb1513f6><a href="/share/docs/linux/#top命令" class="sidebar-link reco-side-top命令" data-v-cb1513f6>top命令</a></li><li class="level-2" data-v-cb1513f6><a href="/share/docs/linux/#nginx代理之后-访问不到静态资源" class="sidebar-link reco-side-nginx代理之后-访问不到静态资源" data-v-cb1513f6>nginx代理之后, 访问不到静态资源</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><!----><div class="kanbanniang" data-v-5775ee02><div class="banniang-container" style="display:;" data-v-5775ee02><div class="messageBox" style="left:68px;bottom:370px;display:none;" data-v-5775ee02>
      欢迎来到我的博客
    </div> <div class="operation" style="right:90px;bottom:40px;display:none;" data-v-5775ee02><i class="kbnfont kbn-ban-home ban-home" data-v-5775ee02></i> <i class="kbnfont kbn-ban-message message" data-v-5775ee02></i> <i class="kbnfont kbn-ban-close close" data-v-5775ee02></i> <a target="_blank" href="https://vuepress-theme-reco.recoluan.com/views/plugins/kanbanniang.html" data-v-5775ee02><i class="kbnfont kbn-ban-info info" data-v-5775ee02></i></a> <i class="kbnfont kbn-ban-theme skin" style="display:;" data-v-5775ee02></i></div> <canvas id="banniang" width="260px" height="420" class="live2d" style="right:200px;bottom:20px;opacity:0.4;" data-v-5775ee02></canvas></div> <div class="showBanNiang" style="display:none;" data-v-5775ee02>
    看板娘
  </div></div><canvas id="vuepress-canvas-cursor"></canvas><!----><div class="RibbonAnimation"></div><!----></div></div>
    <script src="/share/assets/js/app.706684de.js" defer></script><script src="/share/assets/js/3.4685d505.js" defer></script><script src="/share/assets/js/1.b12738fb.js" defer></script><script src="/share/assets/js/50.3918e713.js" defer></script><script src="/share/assets/js/9.4e81f08e.js" defer></script>
  </body>
</html>
